<template>
  <div>
    <guangbopanelCard
      :headerFlag="true"
      :bottomFlag="true"
      :bottomIconFlag="true"
    >
      <template #header>
        <div
          style="display: flex; align-items: center; flex-wrap: wrap; gap: 8px"
        >
          <div style="width: 15%; display: flex; align-items: center">
            <span class="searchColor themfontColor">预约模式</span>
            <el-select
              v-model="state.searchData.appointmentType"
              style="width: 50%; margin-left: 15px"
              placeholder="请输入"
              clearable
            >
              <el-option label="单次播放" value="0"></el-option>
              <el-option label="每天播放" value="1"></el-option>
              <el-option label="每周播放" value="2"></el-option>
              <el-option label="每月播放" value="3"></el-option>
              <el-option label="循环播放" value="4"></el-option>
            </el-select>
          </div>
          <div style="width: 30%; display: flex; align-items: center">
            <span class="searchColor themfontColor">时间选择</span>
            <el-date-picker
              style="margin-left: 15px"
              v-model="state.searchData.time"
              type="datetimerange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              value-format="YYYY-MM-DD HH:mm:ss"
              :default-time="[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 1, 1, 23, 59, 59),
              ]"
            />
          </div>
          <div
            style="
              width: 15%;
              display: flex;
              align-items: center;
              margin-left: 30px;
            "
          >
            <span class="searchColor themfontColor">播放终端</span>
            <el-select
              v-model="state.searchData.userNo"
              style="width: 50%; margin-left: 15px"
              placeholder="请输入"
              clearable
            >
              <el-option
                :label="item.label"
                :value="item.value"
                v-for="(item, index) in state.zhongduanData"
                :key="index"
              ></el-option>
            </el-select>
          </div>
          <div>
            <el-button type="primary" @click="queryFn">查询</el-button>
            <el-button @click="resetFn">重置</el-button>
          </div>
        </div>
      </template>
      <template #article>
        <guangbovxeTB
          ref="guangbovxeTB"
          title="预约管理"
          :tableheads_show="state.tableheads_show"
          :listUrl="state.listUrl"
          :caozuoList="state.caozuoList"
          @addFn="addFn"
          @delAllFn="delAllFn"
          @tiaozheng="tiaozhengFn"
          @shanchu="delFn"
          @startPlan="startPlanFn"
          @stopPlan="stopPlanFn"
        ></guangbovxeTB>
      </template>
    </guangbopanelCard>
    <!-- 新增 -->
    <el-dialog
      draggable
      v-model="state.addFlag"
      width="30%"
      :before-close="handleClose"
    >
      <template #title>
        <span class="themfontColor">{{ state.addTitle }}</span>
      </template>
      <div style="width: 100%">
        <el-form
          ref="addRef"
          :model="state.addForm"
          :rules="state.addRules"
          label-width="100px"
        >
          <el-form-item label="预约模式" prop="appointmentType">
            <el-select
              style="width: 100%"
              @change="changeAppointmentType"
              v-model="state.addForm.appointmentType"
              placeholder="请选择"
              clearable
            >
              <el-option label="单次播放" value="0"></el-option>
              <el-option label="每天播放" value="1"></el-option>
              <el-option label="每周播放" value="2"></el-option>
              <el-option label="每月播放" value="3"></el-option>
              <el-option label="循环播放" value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="播放时间"
            prop="playTime"
            v-if="state.addForm.appointmentType != 4"
          >
            <el-date-picker
              v-if="state.addForm.appointmentType == 0"
              style="width: 100%"
              :disabled-date="disabledDate"
              v-model="state.addForm.playTime"
              placeholder="请选择时间"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
            <el-time-picker
              v-else
              style="width: 100%"
              v-model="state.addForm.playTime"
              placeholder="请选择时间"
              value-format="HH:mm:ss"
            />
          </el-form-item>
          <el-form-item
            label="播放日期"
            prop="time2"
            v-if="state.addForm.appointmentType != 0"
          >
            <el-date-picker
              style="width: 100%"
              v-model="state.addForm.time2"
              type="daterange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              value-format="YYYY-MM-DD"
              :disabled-date="disabledDate"
            />
            <!-- :default-time="[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 1, 1, 23, 59, 59),
              ]" -->
          </el-form-item>
          <el-form-item label="播放模式" prop="playType">
            <el-select style="width: 100%" v-model="state.addForm.playType">
              <el-option label="按次数" value="0"></el-option>
              <el-option label="按时长" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            v-if="state.addForm.playType == 0"
            label="播放次数"
            prop="playCount"
          >
            <el-input
              v-model="state.addForm.playCount"
              :min="1"
              type="Number"
              style="width: 30%"
            ></el-input>
            <span style="margin-left: 10px">次</span>
          </el-form-item>
          <el-form-item
            v-if="state.addForm.playType == 1"
            label="播放时长"
            prop="playCount"
          >
            <el-input
              v-model="state.addForm.playCount"
              :min="1"
              type="Number"
              style="width: 30%"
            ></el-input>
            <span style="margin-left: 10px">分钟</span>
          </el-form-item>
          <el-form-item
            label="按周"
            prop="gapType"
            v-if="state.addForm.appointmentType == 2"
          >
            <el-select v-model="state.addForm.gapType" multiple>
              <el-option label="周一" value="2"></el-option>
              <el-option label="周二" value="3"></el-option>
              <el-option label="周三" value="4"></el-option>
              <el-option label="周四" value="5"></el-option>
              <el-option label="周五" value="6"></el-option>
              <el-option label="周六" value="7"></el-option>
              <el-option label="周日" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="按月"
            prop="gapType"
            v-if="state.addForm.appointmentType == 3"
          >
            <el-select v-model="state.addForm.gapType" multiple>
              <el-option
                :label="item.label"
                :value="item.value"
                v-for="item in state.dateData"
                :key="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="循环周期"
            prop="gapType"
            v-if="state.addForm.appointmentType == 4"
          >
            <el-input
              style="width: 90%"
              oninput="value=value.replace(/[^0-9]/g,'')"
              v-model.number="state.addForm.gapType"
              placeholder="请输入"
            ></el-input>
            <!-- <el-time-picker
              v-model="state.addForm.gapType"
              value-format="HH:mm:ss"
              placeholder="请选择"
            /> -->
            <span style="margin-left: 10px">分钟</span>
          </el-form-item>
          <el-form-item label="播放文件" prop="fileId">
            <el-select
              style="width: 100%"
              v-model="state.addForm.fileId"
              placeholder="请选择"
              clearable
              multiple
            >
              <el-option
                :label="item.fileName"
                :value="item.id"
                v-for="item in state.yinpinData"
                :key="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择分区" prop="fenqu">
            <el-select
              @change="fenquChangeFn"
              style="width: 100%"
              v-model="state.addForm.fenqu"
              placeholder="请选择"
              clearable
            >
              <el-option
                :label="item.label"
                :value="item.value"
                v-for="(item, index) in state.fenquData"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="播放终端" prop="userNo">
            <el-select
              style="width: 100%"
              v-model="state.addForm.userNo"
              placeholder="请选择"
              clearable
              multiple
            >
              <el-option
                :label="item.label"
                :value="item.value"
                v-for="(item, index) in state.bofangzhongduanData"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="播放优先级" prop="forceJoin">
            <el-radio-group v-model="state.addForm.forceJoin">
              <el-radio :label="1" size="large">强插播放</el-radio>
              <el-radio :label="0" size="large">等待播放</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="saveAddFn"> 确定 </el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 临时调整 -->
    <el-dialog
      draggable
      v-model="state.tiaozhengFlag"
      width="25%"
      :before-close="tiaozhenghandleClose"
    >
      <template #title><span class="themfontColor">临时调整</span></template>
      <div style="width: 100%">
        <el-form
          ref="tiaozhengRef"
          :model="state.form"
          :rules="state.tiaozhengRules"
          label-width="100px"
        >
          <el-form-item
            label="播放时间"
            prop="playTime"
            v-if="state.tiaozhengData.appointmentType != 4"
          >
            <el-date-picker
              v-if="state.tiaozhengData.appointmentType == 0"
              style="width: 100%"
              :disabled-date="disabledDate"
              v-model="state.form.playTime"
              placeholder="请选择时间"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
            <el-time-picker
              v-else
              style="width: 100%"
              :disabled-date="disabledDate"
              v-model="state.form.playTime"
              placeholder="请选择时间"
              value-format="HH:mm:ss"
            />
          </el-form-item>
          <el-form-item label="播放文件" prop="fileId">
            <el-select
              style="width: 100%"
              v-model="state.form.fileId"
              placeholder="请输入"
              clearable
              multiple
            >
              <el-option
                :label="item.fileName"
                :value="item.id"
                v-for="item in state.yinpinData"
                :key="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item
            label="调整时间"
            prop="time2"
            v-if="state.tiaozhengData.appointmentType != 0"
          >
            <el-date-picker
              style="width: 100%"
              v-model="state.form.time2"
              type="daterange"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              value-format="YYYY-MM-DD"
              :disabled-date="disabledDate"
            />
            <!-- :default-time="[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 1, 1, 23, 59, 59),
              ]" -->
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="tiaozhenghandleClose">取消</el-button>
          <el-button type="primary" @click="saveTiaozhengFn"> 确定 </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { reactive } from "vue";
import axios from "@/utils/request";
import { table_headers } from "@/assets/table_headers/table_headers";
import dayjs from "dayjs";
import { ElMessage, ElMessageBox, ElNotification } from "element-plus";
import usepagesStore from "@/store/modules/pages";
const userStore = usepagesStore();
const { proxy } = getCurrentInstance();
let state = reactive({
  searchData: {},
  addTitle: "新增",
  addFlag: false,
  tiaozhengFlag: false, //临时调整
  addForm: {
    fileId: [], //播放文件
    userNo: [], //播放终端
    gapType: [],
    forceJoin: 0, //播放优先级
  },
  addRules: {
    appointmentType: [
      {
        required: true,
        message: "请选择预约模式",
        trigger: "change",
      },
    ],
    playTime: [
      {
        required: true,
        message: "请选择播放时间,播放时间不能小于当前的时间",
        trigger: "change",
      },
    ],
    time2: [
      {
        required: true,
        message: "请选择播放日期",
        trigger: "change",
      },
    ],
    playType: [
      {
        required: true,
        message: "请选择播放模式",
        trigger: "change",
      },
    ],
    playCount: [
      {
        required: true,
        message: "请选择播放时长",
        trigger: "change",
      },
    ],
    gapType: [
      {
        required: true,
        message: "请选择",
        trigger: "change",
      },
    ],
    fileId: [
      {
        required: true,
        message: "请选择播放文件",
        trigger: "change",
      },
    ],
    fenqu: [
      {
        required: true,
        message: "请选择选择分区",
        trigger: "change",
      },
    ],
    userNo: [
      {
        required: true,
        message: "请选择播放终端",
        trigger: "change",
      },
    ],
  },
  form: { fileId: [] }, //临时调整
  tiaozhengRules: {
    fileId: [
      {
        required: true,
        message: "请选择播放文件",
        trigger: "change",
      },
    ],
    playTime: [
      {
        required: true,
        message: "请选择播放时间",
        trigger: "change",
      },
    ],
    time2: [
      {
        required: true,
        message: "请选择播放日期",
        trigger: "change",
      },
    ],
  },
  tiaozhengFlag: false,
  zhongduanData: [], //搜索播放终端数据
  bofangzhongduanData: [], //新增弹层播放终端
  yinpinData: [], //所有音频列表
  tiaozhengData: {}, //临时调整
  fenquData: [],
  dateData: [
    //按月
    { label: "1号", value: 1 },
    { label: "2号", value: 2 },
    { label: "3号", value: 3 },
    { label: "4号", value: 4 },
    { label: "5号", value: 5 },
    { label: "6号", value: 6 },
    { label: "7号", value: 7 },
    { label: "8号", value: 8 },
    { label: "9号", value: 9 },
    { label: "10号", value: 10 },
    { label: "11号", value: 11 },
    { label: "12号", value: 12 },
    { label: "13号", value: 13 },
    { label: "14号", value: 14 },
    { label: "15号", value: 15 },
    { label: "16号", value: 16 },
    { label: "17号", value: 17 },
    { label: "18号", value: 18 },
    { label: "19号", value: 19 },
    { label: "20号", value: 20 },
    { label: "21号", value: 21 },
    { label: "22号", value: 22 },
    { label: "23号", value: 23 },
    { label: "24号", value: 24 },
    { label: "25号", value: 25 },
    { label: "26号", value: 26 },
    { label: "27号", value: 27 },
    { label: "28号", value: 28 },
    { label: "29号", value: 29 },
    { label: "30号", value: 30 },
    { label: "31号", value: 31 },
  ],
  caozuoList: [
    //     {
    //   caozuoType: "startPlan",
    //   label: "开始计划",
    // },
    //     {
    //   caozuoType: "stopPlan",
    //   label: "停止计划",
    // },
    {
      caozuoType: "tiaozheng",
      label: "临时调整",
    },
    {
      caozuoType: "shanchu",
      label: "删除",
    },
  ],
  tableheads_show: computed(() => table_headers.t_sip_scheduler),
  listUrl: "/sip/schedule/list",
  addUrl: "/sip/schedule/add",
  editUrl: "/sip/schedule/edit",
  delUrl: "/sip/schedule/",
  detailUrl: "/sip/schedule/",
});
const disabledDate = (time) => {
  return time.getTime() < Date.now() - 8.64e7; // 8.64e7 毫秒数代表一天
};
//开始计划
const startPlanFn = (row) => {
  axios.post(`/sip/schedule/start/${row.id}`, {}).then((res) => {
    if (res.code == 200) {
      proxy.$refs["guangbovxeTB"].getList();
      ElMessage.success(res.msg);
    } else {
      ElMessage.error("已过期");
    }
  });
};
//停止计划
const stopPlanFn = (row) => {
  axios.post(`/sip/schedule/stop/${row.id}`, {}).then((res) => {
    if (res.code == 200) {
      proxy.$refs["guangbovxeTB"].getList();
      ElMessage.success(res.msg);
    } else {
      ElMessage.error("已过期");
    }
  });
};
//新增弹层
const addFn = () => {
  //新增
  console.log("新增");
  state.addTitle = "新增";
  state.addFlag = true;
};
const handleClose = () => {
  //关闭
  console.log("关闭");
  proxy.$refs["addRef"].clearValidate();
  state.addFlag = false;
  state.addForm = {
    fileId: [], //播放文件
    userNo: [], //播放终端
    gapType: [],
    forceJoin: 0, //播放优先级
  };
};
function fenquChangeFn() {
  state.bofangzhongduanData = [];
  let arr = [];
  axios
    .post("/sip/config/user/listNoPage", {
      groupId: state.addForm.fenqu == "0" ? "" : state.addForm.fenqu,
    })
    .then((res) => {
      if (res.data?.length > 0) {
        arr = [];
        res.data.forEach((val) => {
          //搜索播放终端
          arr.push({ label: val.userNumber, value: val.userNumber });
        });
        state.bofangzhongduanData = arr;
      }
    });
}
const changeAppointmentType = (e) => {
  if (e == 4) {
    state.addForm.gapType = "";
  } else {
    state.addForm.gapType = [];
  }
};
const saveAddFn = () => {
  //保存
  // const now = new Date();
  // const year = now.getFullYear(); // 获取当前年份
  // const month = now.getMonth() + 1; // 获取当前月份，注意getMonth()返回的是0-11，所以需要加1
  // const day = now.getDate(); // 获取当前日期
  // let date = year + "-" + month + "-" + day + " ";
  // let times = " " + "00" + ":" + "00" + ":" + "00"; //接口要求的格式实际只用年月日，所以加上时间
  if (state.addForm.playTime) {
    if (state.addForm.appointmentType == 0) {
      //所选时间大于当前实时时间，返回报错
      if (
        dayjs(state.addForm.playTime).isBefore(
          dayjs().format("YYYY-MM-DD HH:mm:ss")
        )
      ) {
        ElMessage.warning("所选时间不能小于当前时间");
        return;
      }
    }
    if (
      state.addForm.appointmentType != 4 &&
      state.addForm.appointmentType != 0
    ) {
      let val = dayjs().format("YYYY-MM-DD") + " " + state.addForm.playTime;
      //所选时间大于当前实时时间，采用时分秒，返回报错
      if (dayjs(val).isBefore(dayjs().format("YYYY-MM-DD HH:mm:ss"))) {
        ElMessage.warning("所选时间不能小于当前时间");
        return;
      }
    }
  }
  let obj = {
    appointmentType: Number(state.addForm.appointmentType), //预约模式,0单次、 1每日、2每周、3每月，4按时间长度重复，比如每1小时重复1次
    playType: Number(state.addForm.playType), //播放模式
    playCount: Number(state.addForm.playCount), //播放次数,时长
    fileId: state.addForm.fileId, //播放文件
    userNo: state.addForm.userNo, //播放终端
    forceJoin: state.addForm.forceJoin, //播放优先级
  };
  if (state.addForm.appointmentType == 0) {
    //单次播放
    obj.name = "单次播放";
    obj.playTime = state.addForm.playTime; //播放时间
  } else if (state.addForm.appointmentType == 1) {
    //每天播放
    obj.name = "每天播放";
    obj.playTime = "1970-01-01" + " " + state.addForm.playTime; //播放时间
    obj.beginTime = state.addForm.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd HH:mm:ss
    obj.endTime = state.addForm.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd HH:mm:ss
  } else if (
    state.addForm.appointmentType == 2 ||
    state.addForm.appointmentType == 3
  ) {
    //每周/月播放
    obj.name = state.addForm.appointmentType == 2 ? "每周播放" : "每月播放";
    obj.playTime = "1970-01-01" + " " + state.addForm.playTime; //播放时间
    obj.beginTime = state.addForm.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd HH:mm:ss
    obj.endTime = state.addForm.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd HH:mm:ss
    obj.gapType = state.addForm.gapType.join(","); //按周，多个以半角逗号分割，1-7，星期一到星期日
  } else if (state.addForm.appointmentType == 4) {
    //循环播放
    obj.name = "循环播放";
    obj.beginTime = state.addForm.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd HH:mm:ss
    obj.endTime = state.addForm.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd HH:mm:ss
    obj.gapType = state.addForm.gapType; //按周，多个以半角逗号分割，1-7，星期一到星期日
  }
  console.log(obj, "obj");
  proxy.$refs["addRef"].validate((isOk) => {
    if (isOk) {
      axios.post(state.addUrl, obj).then((res) => {
        if (res.code == 200) {
          ElMessage.success("已保存");
          handleClose();
          // state.addFlag = false;
          // state.addForm = {
          //   fileId: [], //播放文件
          //   userNo: [], //播放终端
          //   gapType: [],
          //   forceJoin: 0, //播放优先级
          // };
          proxy.$refs["addRef"].clearValidate();
          proxy.$refs["guangbovxeTB"].getList();
        }
      });
    }
  });
};
const delAllFn = () => {
  if (userStore.records.length == 0) {
    ElMessage.warning("请选择要删除的记录");
    return;
  } else {
    let str = [];
    userStore.records.forEach((item) => {
      str.push(item.id);
    });
    ElMessageBox.confirm("确认删除?", "提示", {
      confirmButtonText: "删除",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        axios.delete(state.delUrl + str.join(",")).then((res) => {
          ElMessage.success("删除成功");
          userStore.records = [];
          proxy.$refs["guangbovxeTB"].getList();
        });
      })
      .catch(() => {});
  }
};
const tiaozhengFn = (row) => {
  //临时调整
  state.form.fileId = [];
  let arr = [];
  console.log(row, "临时调整");
  state.tiaozhengData = row;
  state.tiaozhengFlag = true;
  if (row.appointmentType != 0 || row.appointmentType != 4) {
    state.form.playTime = row.playTime;
  } else if (row.appointmentType == 0) {
    let timePart = row.playTime.split(" ")[1];
    state.form.playTime = timePart;
  }
  row?.fileList.forEach((item) => {
    arr.push(item.id);
  });
  state.form.fileId = arr;
  if (row.appointmentType != 0) {
    state.form.time2 = [row.beginTime, row.endTime];
  }
};
const tiaozhenghandleClose = () => {
  //临时调整关闭
  state.tiaozhengFlag = false;
  state.form = { fileId: [] };
  // proxy.$refs["tiaozhengRef"].clearValidate();
};
const saveTiaozhengFn = () => {
  //临时调整保存
  let obj = {
    id: state.tiaozhengData.id,
    name: state.tiaozhengData.name,
    appointmentType: state.tiaozhengData.appointmentType, //预约模式
    playType: state.tiaozhengData.playType, //播放模式
    playCount: state.tiaozhengData.playCount, //播放次数,时长
    fileId: state.form.fileId, //播放文件
    gapType: state.tiaozhengData.gapType, //播放间隔
    userNo: state.tiaozhengData.userNo, //播放终端
    triggerStatus: state.tiaozhengData.triggerStatus,
    uuid: state.tiaozhengData.uuid,
    xxlJobId: state.tiaozhengData.xxlJobId,
    forceJoin: state.tiaozhengData.forceJoin, //播放优先级
  };
  if (state.tiaozhengData.appointmentType == 0) {
    //单次播放
    obj.playTime = state.form.playTime; //播放时间
    obj.beginTime = state.tiaozhengData.beginTime; //开始日期，标准时间格式yyyy-MM-dd
    obj.endTime = state.tiaozhengData.endTime; //结束日期，标准时间格式yyyy-MM-dd
  } else if (state.tiaozhengData.appointmentType == 1) {
    //每天播放
    obj.playTime = state.form.playTime
      ? "1970-01-01" + " " + state.form.playTime
      : null; //播放时间
    obj.beginTime = state.form.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd
    obj.endTime = state.form.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd
  } else if (
    state.tiaozhengData.appointmentType == 2 ||
    state.tiaozhengData.appointmentType == 3
  ) {
    //每周/月播放
    obj.playTime = state.form.playTime
      ? "1970-01-01" + " " + state.form.playTime
      : null; //播放时间
    obj.beginTime = state.form.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd
    obj.endTime = state.form.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd
  } else if (state.tiaozhengData.appointmentType == 4) {
    //循环播放
    obj.playTime = state.form.playTime
      ? "1970-01-01" + " " + state.form.playTime
      : null; //播放时间
    obj.beginTime = state.form.time2?.[0]; //开始日期，标准时间格式yyyy-MM-dd
    obj.endTime = state.form.time2?.[1]; //结束日期，标准时间格式yyyy-MM-dd
  }
  console.log(obj, "obj");
  proxy.$refs["tiaozhengRef"].validate((isOk) => {
    if (isOk) {
      axios.post(state.editUrl, obj).then((res) => {
        if (res.code == 200) {
          ElMessage.success(res.msg);
          state.tiaozhengFlag = false;
          state.form = {};
          proxy.$refs["guangbovxeTB"].getList();
        } else {
          ElMessage.error(res.msg);
        }
      });
    }
  });
};
const delFn = (row) => {
  //删除
  // state.tiaozhengData = row;
  // console.log(row, '删除');
  ElMessageBox.confirm("确认删除?", "提示", {
    confirmButtonText: "删除",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      axios.delete(state.delUrl + row.id).then((res) => {
        ElMessage.success("删除成功");
        proxy.$refs["guangbovxeTB"].getList();
      });
    })
    .catch(() => {});
};
const queryFn = () => {
  console.log(state.searchData, "queryFn");
  let obj = {};
  obj.appointmentType = state.searchData.appointmentType;
  obj.queryStartTime = state.searchData?.time?.[0];
  obj.queryEndTime = state.searchData?.time?.[1];
  obj.userNo = state.searchData.userNo;
  proxy.$refs["guangbovxeTB"].state.searchData = obj;
  proxy.$refs["guangbovxeTB"].getList();
};
const resetFn = () => {
  state.searchData = {};
  proxy.$refs["guangbovxeTB"].state.searchData = {};
  proxy.$refs["guangbovxeTB"].getList();
};
const getSelectList = () => {
  let arr = [];
  axios
    .post("/sip/config/user/listNoPage", {
      groupId: "",
    })
    .then((res) => {
      if (res.data?.length > 0) {
        arr = [];
        res.data.forEach((val) => {
          //搜索播放终端
          arr.push({ label: val.userNumber, value: val.userNumber });
        });
        state.zhongduanData = arr;
      }
    });
};
const getAllYinpinList = () => {
  let arr = [];
  //所有音频列表
  axios.post("/sip/config/file/list", {}).then((res) => {
    res.data.list.forEach((item) => {
      if (item.type == 0) {
        arr.push(item);
      }
    });
    state.yinpinData = arr;
  });
};
const getTreeList = () => {
  //左分区
  let arr = [];
  let total = 0;
  axios.post("/sip/config/group/listNoPage", {}).then((res) => {
    if (res.data?.length >= 0) {
      state.treeData = [];
      total = getSumFromObjects(res.data, "TerminalCount");
      function getSumFromObjects(arr, prop) {
        return arr.reduce((a, curr) => a + curr[prop], 0);
      }
      arr.push({
        id: 0,
        label: "全部",
        value: "0",
      });
      res.data.forEach((item) => {
        arr.push({
          id: item.id,
          label: item.groupName,
          value: item.id,
        });
      });
      state.fenquData = arr;
    }
  });
};
onMounted(() => {
  getSelectList();
  // getHeader();
  getAllYinpinList(); //所有音频列表
  getTreeList(); //选择分区
  queryFn();
});
</script>
<style lang="scss" scoped>
</style>